<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ChannelVisitUserDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateChannelVisitUserRequest;
use App\Http\Requests\UpdateChannelVisitUserRequest;
use App\Repositories\ChannelVisitUserRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ChannelVisitUserController extends AppBaseController
{
    /** @var  ChannelVisitUserRepository */
    private $channelVisitUserRepository;

    public function __construct(ChannelVisitUserRepository $channelVisitUserRepo)
    {
        $this->channelVisitUserRepository = $channelVisitUserRepo;
    }

    /**
     * Display a listing of the ChannelVisitUser.
     *
     * @param ChannelVisitUserDataTable $channelVisitUserDataTable
     * @return Response
     */
    public function index(ChannelVisitUserDataTable $channelVisitUserDataTable)
    {
        return $channelVisitUserDataTable->render('backend.channel_visit_users.index');
    }

    /**
     * Show the form for creating a new ChannelVisitUser.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.channel_visit_users.create');
    }

    /**
     * Store a newly created ChannelVisitUser in storage.
     *
     * @param CreateChannelVisitUserRequest $request
     *
     * @return Response
     */
    public function store(CreateChannelVisitUserRequest $request)
    {
        $input = $request->all();

        $channelVisitUser = $this->channelVisitUserRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Channel Visit User']));

        return redirect(route('channelVisitUsers.index'));
    }

    /**
     * Display the specified ChannelVisitUser.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $channelVisitUser = $this->channelVisitUserRepository->findWithoutFail($id);

        if (empty($channelVisitUser)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Visit User']));

            return redirect(route('channelVisitUsers.index'));
        }

        return view('backend.channel_visit_users.show')->with('channelVisitUser', $channelVisitUser);
    }

    /**
     * Show the form for editing the specified ChannelVisitUser.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $channelVisitUser = $this->channelVisitUserRepository->findWithoutFail($id);

        if (empty($channelVisitUser)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Visit User']));

            return redirect(route('channelVisitUsers.index'));
        }

        return view('backend.channel_visit_users.edit')->with('channelVisitUser', $channelVisitUser);
    }

    /**
     * Update the specified ChannelVisitUser in storage.
     *
     * @param  int              $id
     * @param UpdateChannelVisitUserRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateChannelVisitUserRequest $request)
    {
        $channelVisitUser = $this->channelVisitUserRepository->findWithoutFail($id);

        if (empty($channelVisitUser)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Visit User']));

            return redirect(route('channelVisitUsers.index'));
        }

        $channelVisitUser = $this->channelVisitUserRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Channel Visit User']));

        return redirect(route('channelVisitUsers.index'));
    }

    /**
     * Remove the specified ChannelVisitUser from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $channelVisitUser = $this->channelVisitUserRepository->findWithoutFail($id);

        if (empty($channelVisitUser)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Visit User']));

            return redirect(route('channelVisitUsers.index'));
        }

        $this->channelVisitUserRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Channel Visit User']));

        return redirect(route('channelVisitUsers.index'));
    }
}
